const express = require('express')

const app = express()

app.get('/home', (req, res) => {
  res.send('前台首页')
})

const checkCodeMiddleware = (req, res, next) => {
  if (req.query.code === '521') {
    next()
  } else {
    res.send('暗号错误')
  }
}

app.get('/admin', checkCodeMiddleware, (req, res) => {
  res.send('后台首页')
})

app.get('/setting', checkCodeMiddleware, (req, res) => {
  res.send('设置首页')
})

app.get('*', (req, res) => {
  res.send('<h1>404 Not Found</h1>')
})

app.listen(3000, () => {
  console.log('服务已经启动，端口3000 正在监听中...')
})
